// --- Copyright (c) 2006-2008 Stefan Kyntchev ---
// This software is written and copyrighted by Stefan Kyntchev 
// and BeyondPod Team members. All rights are reserved.
// Author contact: support@beyondpod.mobi
// ------------------------------------------------------------------------
// This file is part of BeyondPod RSS Feed Reader and Podcast manager
// (www.codeplex.com/BeyondPod) 
// BeyondPod is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
//  
// BeyondPod is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more details. 
//  
// You should have received a copy of the GNU General Public License
// along with BeyondPod. If not, see <http://www.gnu.org/licenses/>
// ------------------------------------------------------------------------
// COPYRIGHT NOTICE: This copyright notice may NOT be removed, obscured or modified 
// without written consent from the author.
// --- End copyright notice --- 


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using svs.Mobile.BeyondMedia.FeedCore;

#if Smartphone
#endif

namespace svs.Mobile.BeyondMedia.Forms.Settings
{
	public partial class Settings : Form
	{

		public class SettingPage
		{
			public SettingPage(string pageName, string pageDescription, SettingsPageHolderForm.SettingsPages page)
			{
				PageName = pageName;
				Page = page;
				PageDescription = pageDescription;
			}

			public string PageName
			{
				get;
				set;
			}

			public string PageDescription
			{
				get; set;
			}

			public SettingsPageHolderForm.SettingsPages Page
			{
				get;
				set;
			}
		}


		private bool _ShouldReloadRepository = false;

		public Settings()
		{
			InitializeComponent();
		}


		public bool ShouldReloadRepository
		{
			get { return _ShouldReloadRepository; }
		}

		private void OnLoad(object sender, EventArgs e)
		{
			var list = new List<SettingPage>();

			list.Add(new SettingPage(GeneralSettings.PageName, GeneralSettings.PageDescription, GeneralSettings.PageID));
			list.Add(new SettingPage(PlayerSettings.PageName, PlayerSettings.PageDescription, PlayerSettings.PageID));
			list.Add(new SettingPage(FeedContentSettings.PageName, FeedContentSettings.PageDescription, FeedContentSettings.PageID));

			PageList.SetPages(list);
			PageList.PageSelected += OnPageSelected;
		}

		private void OnPageSelected(SettingPage selected)
		{
			SettingsPageHolderForm page = new SettingsPageHolderForm(selected.Page);
			page.Text = selected.PageName;
			if (page.ShowDialog() == DialogResult.OK)
			{
				Application.DoEvents();

				Configuration.SaveSettings();

				//Check if we made a change that requres a Repository reload on close
				if (!_ShouldReloadRepository && page.ShouldReloadRepositoryOnDone)
				{
					_ShouldReloadRepository = true;
				}
			}
		}

		private void Done_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}